package web;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.ViewProductStock;

/**
 * Servlet implementation class SearchServlet
 */
public class SearchServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SearchServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ViewProductStock products = new ViewProductStock();
		System.out.println(request.getServletPath());
		try {
			if(request.getServletPath().equals("/searchcocktail.do")){
				request.setAttribute("produse", products.getStock(request.getParameter("searchvalue"), "", true));
				System.out.println("cocktail");
			}
			else if (request.getServletPath().equals("/searchstock.do")){
				request.setAttribute("produse", products.getStock(request.getParameter("searchvalue"), "", false));
				System.out.println("stock");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		RequestDispatcher view = request.getRequestDispatcher("inventarproduse.jsp"); // Se apeleaza jsp cu variabila view
		view.forward(request, response);		//Se trimite mai departe variabilele request si response	
	}

}
